import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class ScannerImpl {

	
	public static void main(String[] args) {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		char[] cbuf;
		Map<String,String> searchMap = new LinkedHashMap<String,String>();
		// This is just a demo. You can use any logic here to read from stdin -
		// till End of File or End of Stream etc.,
		cbuf = new char[1024];
		try {
			in.read(cbuf);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		String inputs = new String(cbuf);
		args = inputs.split(" ");
		if (args == null) {
			System.out.print("FAILURE");
			System.exit(1);
		}

		if (args.length == 1) {
			File f = new File(args[0].trim());
			if (f.exists()) {
				System.out.print("READY");
				System.exit(0);
			} else {
				System.out.print("FAILURE");
				System.exit(1);
			}
		}

		for (int i = 1; i < args.length; i++) {
			String arg = args[i].trim();
			if (arg.contains("T=") || arg.contains("R=")) {
				String ids = arg.substring(arg.indexOf("=") + 1);
				String[] idArr = ids.split(",");
				for (int j = 0; j < idArr.length; j++) {
					if(arg.contains("T=")){
						searchMap.put(idArr[j],null);
					}
					if(arg.contains("R=")){
						searchMap.put(idArr[j],null);
					}
				}
			}
		}
		Scanner scan = null;
		try {
			File f = new File(args[0].trim());			
			scan = new Scanner(f);
			scan.useDelimiter("\n");
			int count = 0;
			while(scan.hasNext()){
				String token = scan.nextLine();
				List<String> searchList = new ArrayList<String>(searchMap.keySet());
				for(int i = 0; i < searchList.size(); i++){					
					String p = searchList.get(i);
					if(p.startsWith("TXN") && token.matches(p+",[0-9A-Z]*")){					
						searchMap.put(p,token.substring(token.indexOf(",")+1));
						count ++;
						if(count == searchMap.size()){
							break;
						}
					}
					else if(p.startsWith("REF") && token.matches("TXN[0-9A-Z]*,"+p)){						
						searchMap.put(p,token.substring(0,token.indexOf(",")));
						count++;
						if(count == searchMap.size()){
							break;
						}
					}					
				}
				if(count == searchMap.size()){
					break;
				}
			}
			scan.close();
			for(Iterator<String> itr = searchMap.keySet().iterator();itr.hasNext();){
				String s = itr.next();
				String value = searchMap.get(s);
				System.out.print(( value!= null)?value:"FAILURE" );
				if(itr.hasNext()){
					System.out.print(",");
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv
// C:\sivravis\dev\studies\BOC2014\codeContest1M.csv
// C:\\sivravis\\dev\\studies\\BOC2014\\sampleInput.csv T=TXN00000000000000043179168899325,TXN00000000000000050209776656593 R=REF00000000000000116009591331268
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest10M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
// System.out.println(count++ + " times read " + bytesRead + " Bytes.");
